package com.usian.controller;

import com.usian.config.FeignProduct;
import com.usian.config.ResponseResult;
import com.usian.pojo.Product;
import com.usian.pojo.Supply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private FeignProduct feignProduct;
    @RequestMapping("/findAll")
    public List<Product> findAll(@RequestBody Product product){
return feignProduct.findAll(product);
    }
    @RequestMapping("/findAllss")
    public List<Supply> findAllss(){
        return feignProduct.findAllss();
    }
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody Product product){
        try {
            feignProduct.insert(product);
            return ResponseResult.errorResult(200,"添加成功1");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(500,"添加失败");
        }
    }
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Product product){
        try {
            feignProduct.update(product);
            return ResponseResult.errorResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(500,"修改失败");
        }
    }
    @PostMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Integer id){
        try {
            feignProduct.delete(id);
            return ResponseResult.errorResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(500,"删除失败");
        }
    }
    @GetMapping("/findByid")
    public Product findByid(@RequestParam("id") Integer id){
        return feignProduct.findByid(id);
    }
}
